<?php
/**
 * API permissions tab template for integration activation dialog.
 *
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 *
 * @var \Magento\Integration\Block\Adminhtml\Integration\Activate\Permissions\Tab\Webapi $block
 */

// @codingStandardsIgnoreFile

?>
<fieldset class="admin__fieldset form-inline entry-edit">
    <?php if ($block->isTreeEmpty()): ?>
        <p class="empty"><?php /* @escapeNotVerified */ echo __('No permissions requested'); ?></p>
    <?php else: ?>
        <div class="field" data-role="tree-resources-container">
            <div class="control">
                <div id="resource-tree" class="tree x-tree" data-role="resource-tree"></div>
            </div>
        </div>
    <?php endif ?>
</fieldset>
<?php if (!$block->isTreeEmpty()): ?>
    <script>
        require(["jquery", "Magento_User/js/roles-tree"], function($){
            $.widget('mage.rolesTree', $.mage.rolesTree, {
                _checkNode: function(event) {},
                _checkNodes: function() {
                    this._super();
                    this.element.jstree('disable_hotkeys').jstree('hide_checkboxes')
                        .find('li.jstree-unchecked').hide().end().find('li.jstree-checked').attr('rel', 'disabled');
                }
            });

            $('[data-role="resource-tree"]').rolesTree({
                'treeInitData': <?php /* @escapeNotVerified */ echo $block->getResourcesTreeJson() ?>,
                'treeInitSelectedData': <?php /* @escapeNotVerified */ echo $block->getSelectedResourcesJson() ?>
            });
        });
    </script>
<?php endif ?>
